package com.company.jdk8;

import org.junit.Test;

import javax.sound.midi.Soundbank;
import java.net.Socket;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @ProjectName: 复习java
 * @Package: com.company.jdk8
 * @ClassName: StreamApiTest2
 * @Author: wym
 * @Date: 2020/11/10 14:52
 * @Version: 1.0
 * 规约
 */
public class StreamApiTest2  {
    @Test
    public void  test(){
        //1-10 的和
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        Integer reduce = list.stream().reduce(0, Integer::sum);
        System.out.println(reduce);
        //练习2:: 计算所有员工工资的总和
        Stream<Employee> stream = EmployeeData.getEmployees().stream();
        Optional<Double> reduce1 = stream.map(e -> e.getSalary())
                .reduce((e1, e2) -> {
                    return e1 + e2;
                });
        System.out.println(reduce1);
    }

    /**
     * 搜集 collect(Collector c)
     */
    @Test
    public  void  test2(){
        List<Employee> employees = EmployeeData.getEmployees();
        List<String> collect = employees.stream().filter(e -> e.getSalary() > 6000).map(e -> e.getName()).collect(Collectors.toList());
        System.out.println(collect);
    }
}
